<template>
  <tm-sheet color="#f5f5f5" :padding="[0,20]" :margin="[0]">
    <tm-form
      ref="form"
      v-model="formData"
      :label-width="220"
      :padding="[0]"
      :margin="[0]"
      :round="0"
      class="primaryForm-wrap"
    >
      <tm-form-item
        v-for="(item, index) in fields"
        :key="index"
        :label="item.name"
        :field="item.id"
        :show-error="false"
      >
        <tm-input
          :ready-only="true"
          :inputPadding="[20, 0]"
          :model-value="getFieldText(item)"
          :transprent="true"
          align="right"
          disabled
          placeholder="-"
        >
        </tm-input>
      </tm-form-item>
    </tm-form>
  </tm-sheet>

</template>
<script lang="ts" setup>
import OrgCtrl from '@/ts/controller'
import { Ref, computed } from 'vue'
import { CustomFormType } from '../../workTypes'
import { FieldModel } from '@/ts/base/model'

type IProps = {
  formInfo: CustomFormType
}
const props = defineProps<IProps>()
console.log(props,'props')
const fields: Ref<FieldModel[]> = computed(() => props.formInfo?.fields)

const formData = computed(() => props.formInfo?.data[0].after[0] ?? {})

const getFieldText = (field: FieldModel) => {
  const _value = formData.value[field.id]
  switch (field.valueType) {
    case '描述型':
    case '日期型':
    case '时间型':
    case '数值型':
      return _value ?? '-'
    case '选择型':
    case '分类型':
      return field.lookups!.find(v => v.value === _value)?.text
    case '用户型':
      return OrgCtrl.user.findShareById(_value)?.name
    default:
      return _value ?? '-'
  }
}
</script>

<style lang="scss" scoped>
</style>
